package cloneExample;

import java.util.ArrayList;

/**
 * 利用cloneable 接口 告知并实现
 */
public class CloneExample1 {
	public static void main(String[] args) throws CloneNotSupportedException {
		clone1();
		ArrayList<Object> objects = new ArrayList<>();
	}

	private static void clone1() throws CloneNotSupportedException {
		Address address = new Address(110, "beijing");
		People p1 = new People(1, "Java", address);
		People p2 = (People) p1.clone();
		p1.getAddress().setCity("guangzhou");
		// 两个内容不一致，说明了是两个对象。
		System.out.println("p1:" + p1.getAddress().getCity()); // guangzhou
		System.out.println("p2:" + p2.getAddress().getCity()); // beijing
	}

}
